﻿using MarvellousWorks.PracticalPattern.Concept.Configurating;
using MarvellousWorks.PracticalPattern.FactoryMethod.Batch;
using MarvellousWorks.PracticalPattern.FactoryMethod.GenericFactory;

//using MarvellousWorks.PracticalPattern.FactoryMethod.Example1;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MarvellousWorks.PracticalPattern
{
    internal class Program
    {
        static void Main(string[] args)
        {
            /*
             * 使用配置类的四个主要元素
             * ConfigurationSectionGroup
             * ConfigurationSection
             * ConfigurationElementCollection
             * ConfigurationElement
             */
            /* DelegatingParagramConfigurationSection section = ConfigurationBorker.Delegating;
             var res = section.Pictures["EventHandler"].Colorized;
             Console.WriteLine(res);
             var res2 = section.Examples["MulticastNotify"].Description;
             Console.WriteLine(res2);
             GenericParagramConfigurationSection generic = ConfigurationBorker.Generics;
             var count = generic.Diagrams.Count;
             Console.WriteLine(count);
             Console.WriteLine(generic.Diagrams["ClassicBuilder"].Description);
             Console.WriteLine(generic.Diagrams["ClassicBuilder"].Name);
             Console.WriteLine(generic.Examples.Count);
             Console.WriteLine(generic.Examples["RawGenericFactory"].Description);*/

            #region 简单工厂
            //测试 classic 工厂
            //Factory factory = new Factory();
            //IProduct product = factory.Create();
            //Console.WriteLine(object.ReferenceEquals( product.GetType(),typeof(ProductA)));

            // 静态工厂 classic
            //IProduct product = ProductFactory.Create(Category.B);
            //Console.WriteLine(object.ReferenceEquals(product.GetType(), typeof(ProductA)));
            //Console.WriteLine(object.ReferenceEquals(product.GetType(), typeof(ProductB)));

            #endregion


            // 抽象工厂
            //IFactory factory = new FactoryA();
            //IProduct product = factory.Create();
            //Console.WriteLine(object.ReferenceEquals(product.GetType(), typeof(ProductA)));

            // 批量工厂
           /* Client client = new Client();
            IProduct[] products = client.Products();
            Console.WriteLine(products.Length);
            for (int i = 0; i < 2; i++)
            {
                Console.WriteLine(products[i].Name);
            }
            Console.WriteLine();
            for (int i = 2; i < 5; i++)
            {
                Console.WriteLine(products[i].Name);
            }*/


            IFactory<CalculatorHandler> factory = new CalculatorHandlerFactory();
            var handler = factory.Create();
            Console.WriteLine($"{1+2+3} == {handler(1,2,3)}");
            Console.WriteLine("***************************************");
            Calculator calculator = new Calculator();
            var res = calculator.Add2(new int[] {1,2,3});
            Console.WriteLine(res);

        }
    }
}
